package com.briup.day15;

import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lining
 * @date 2024/1/25 10:27
 */
public class Test2 {
    public void printList(List<?> list){//可以接受任意类型的元素集合
//        list.add(1.1); 不能添加元素
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
    public void printNumList(List<? extends Number> list){//打印的都是包装类的元素
        //List<Integer> <Double> <Long>
        System.out.println(list);
        //list 指向Number类型及其对应的子类类型的泛型集合
        list = new ArrayList<Integer>();
        list = new ArrayList<Double>();
    }
    public void print(List<? super Integer> list){
        //
        list = new ArrayList<Integer>();
        list = new ArrayList<Number>();
        list = new ArrayList<Object>();
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
//        List<Object> list2 = new ArrayList<String>();
        Test2 t = new Test2();
        t.printList(new ArrayList<String>());
        t.printList(new ArrayList<Integer>());
        t.printList(new ArrayList<Double>());
        t.printNumList(new ArrayList<Integer>());
        t.printNumList(new ArrayList<Double>());
        t.printNumList(new ArrayList<Long>());
        t.printNumList(new ArrayList<Number>());
//        t.printNumList(new ArrayList<String>());
        //super 表示下限  extends 表示上限
        List<? super Number> nums = new ArrayList<Object>();
    }
}
